/*
 *
 *
 */

#ifndef GKT_BACKBOARD_H
#define GKT_BACKBOARD_H

#include "gkt_types.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
	GKT_BB_MODULE_COMMON = 0,
	GKT_BB_MODULE_DOOR_LOCK,
	GKT_BB_MODULE_DOOR_KEY,
	GKT_BB_MODULE_INDOOR_BELL,
	GKT_BB_MODULE_NETWORK,
	GKT_BB_MODULE_CAT_EYE,
	GKT_BB_MODULE_FACTORY_RESET,
	GKT_BB_MODULE_VISUAL_INTERCOM,
	GKT_BB_MODULE_MAX
} gkt_bb_module_e;

#ifdef GKT_CONFIG_BB_OPCODE_MAX
#define GKT_BB_OPCODE_MAX	GKT_CONFIG_BB_OPCODE_MAX
#else
#define GKT_BB_OPCODE_MAX	32
#endif

/* status */
typedef enum {
	GKT_BB_STATUS_NONE = 0,

	GKT_BB_STATUS_SUCCESS,
	GKT_BB_STATUS_INPROCESS,
	GKT_BB_STATUS_START,
	GKT_BB_STATUS_COMPLETE,
	GKT_BB_STATUS_SINGLE_START,
	GKT_BB_STATUS_SINGLE_COMPLETE,
	GKT_BB_STATUS_NEEDLESS,

	GKT_BB_STATUS_ERR_BASE = 0x20,
	GKT_BB_STATUS_ERR_MODULE_ID = GKT_BB_STATUS_ERR_BASE,
	GKT_BB_STATUS_ERR_OPCODE,
	GKT_BB_STATUS_ERR_DATA_VALUE,
	GKT_BB_STATUS_ERR_DATA_LEN,
	GKT_BB_STATUS_ERR_PARAMS,
	GKT_BB_STATUS_ERR_BUSY,
	GKT_BB_STATUS_ERR_TIMEOUT,
	GKT_BB_STATUS_ERR_NO_MEMORY,
	GKT_BB_STATUS_ERR_NO_RESOURCE,
	GKT_BB_STATUS_ERR_FORBID,
	GKT_BB_STATUS_ERR_UNKNOWN,		/*未知错误*/

	GKT_BB_STATUS_ERR_TEST_BASE = 0x40,
	GKT_BB_STATUS_ERR_TEST_NO_UVC = GKT_BB_STATUS_ERR_TEST_BASE,   // UVC 镜头异常
	GKT_BB_STATUS_ERR_TEST_CONNECT_AP_FAIL, // AP连接异常
	GKT_BB_STATUS_ERR_TEST_RSSI_WEAK,			// WIFI信号差

	GKT_BB_STATUS_MAX
} gkt_bb_status_e;

/* notify type */
enum {
	GKT_BB_NOTIFY_LOCAL = 0,
	GKT_BB_NOTIFY_PEER,
	GKT_BB_NOTIFY_MAX
};

enum {
	GKT_BB_APP_PACKET_MODULE_ID = 0,
	GKT_BB_APP_PACKET_OPCODE,
	GKT_BB_APP_PACKET_MINSIZE
};

typedef void (*gkt_bb_module_notify_fn)(int type, 
				const uint8_t *data, int length_retval);

int gkt_backboard_init(void);

int gkt_backboard_is_ready(void);

void gkt_backboard_register_module(
			gkt_bb_module_e module_id, uint32_t opcode_max,
			const gkt_bb_module_notify_fn notify);

int gkt_backboard_send_data(const uint8_t *data, 
			uint32_t length);


//backbaord common module function
enum {
	GKT_BACKBAORD_COMMON_STATUS_FACTORY_RESET_INPROCESS = 0,
	GKT_BACKBAORD_COMMON_STATUS_FACTORY_RESET_COMPLETE,
	GKT_BACKBAORD_COMMON_STATUS_FACTORY_RESET_FAILED,
	GKT_BACKBAORD_COMMON_STATUS_CHECK_PAIRING_SUCCESS,
	GKT_BACKBAORD_COMMON_STATUS_CHECK_PAIRING_FAILED,

	GKT_BACKBAORD_COMMON_STATUS_MAX
};

/* backbaord common notify type */
typedef enum {
	GKT_BACKBAORD_COMMON_NOTIFY_TYPE_STATUS = 0,
	GKT_BACKBAORD_COMMON_NOTIFY_TYPE_MAX
} gkt_backboard_common_notify_type_e;
typedef void (*gkt_backboard_common_notify_fn)(uint32_t type, uint32_t data);
void gkt_backboard_common_register_notify(gkt_backboard_common_notify_fn notify);
int gkt_backboard_common_get_info(void);
int gkt_backboard_common_init(void);
int gkt_backboard_notify_frontboard_standby_status(void);
int gkt_backboard_factory_reset(uint32_t module_bits);
uint16_t gkt_backboard_get_hw_version(void);
uint16_t gkt_backboard_get_sw_version(void);
#if defined(GKT_CONFIG_BACKBOARD_CHECK_PAIRING) && GKT_CONFIG_BACKBOARD_CHECK_PAIRING
int gkt_backboard_check_pairing(void);
#endif

#ifdef __cplusplus
}
#endif

#endif

